package com.honey.mybatis.generator.dao;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.Clazz;
import com.honey.core.compiler.CompilationException;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.dbmapping.structure.Schema;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.mybatis.generator.AbstractClass;
import com.honey.mybatis.generator.MybatisPlugin;
import com.honey.mybatis.generator.entity.EntityConstant;

public class BaseDaoImplements extends AbstractClass {
	
	public BaseDaoImplements(MybatisPlugin belongPlugin,
			IntrospectSchema introspectSchema,
			IntrospectSchemaColumn introspectSchemaColumn) {
		super(belongPlugin, introspectSchema, introspectSchemaColumn);
	}

	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractClass#getAbstractJavaCompilation()
	 */
	@Override
	protected AbstractJavaCompilation getAbstractJavaCompilation()
			throws CompilationException {
		Schema schema = introspectSchema.getSchema();
		Clazz answer = null;
		try {
			answer =new Clazz(super.getBaseDaoImplementsClassType(null,"<"+EntityConstant.ENTITY_GENERIC_NAME+" extends "+super.getEntityInterfaceName(schema)+">"));
			
			answer.addImportedType(super.getModelClassType(introspectSchema.getSchema()));
			answer.addImportedType(DaoConstant.ROW_BOUNDS);
			answer.addImportedType(DaoConstant.SQL_RUNNER);
			answer.addImportedType(DaoConstant.SQL_SESSION_PACKAGE);
			answer.addImportedType(super.getEntityInterfaceType(null));
			
			//注入模型
			answer.addField(super.getInversionModel().inversionFiled(null));
			answer.addMethod(super.getInversionModel().inversionMethod(null));
			
		} catch (CompilationException e) {
			e.printStackTrace();
		}
		return answer;
	}
	
	@Override
	protected FullyQualifiedJavaType getType() {
		
		return null;
	}

	@Override
	protected FullyQualifiedJavaType getSuperClass() {
		return super.getInversionModel().extend();
	}

	
	
}
